package org.liveboardgames.agricola.control.delegates.action.processor
{
	import org.liveboardgames.agricola.control.events.intern.ActionEvent;
	import org.liveboardgames.agricola.model.AgricolaModelLocator;
	import org.liveboardgames.agricola.vo.action.Action;
	import org.liveboardgames.agricola.vo.player.Player;
	import org.liveboardgames.common.utils.collections.SortUtils;
	
	import mx.collections.ListCollectionView;

	public class FirstPlayerActionProcessor extends ActionProcessor
	{

		public function FirstPlayerActionProcessor(action:Action):void
		{
			super(action);
		}

		override public function execute():void
		{
			// Re-order the list of players
			// TODO: maybe pass the game as parameter ?
			var players:ListCollectionView = AgricolaModelLocator.getInstance().game.players;
			var newFirstPlayer:Player = action.target as Player;
			SortUtils.circularPermutation(players, newFirstPlayer);
			
			// Notify that the action has been completed
			this.dispatchEvent(new ActionEvent(ActionEvent.ACTION_COMPLETE));
		}
	}
}